package com.itheima.bean.processor;

import com.itheima.bean.dao.UserDao;
import org.springframework.beans.BeanMetadataAttribute;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.GenericBeanDefinition;

/**
 *  BeanFactory 对象工厂 代指spring容器
 *  Post 后置
 *  Processor 处理器
 *
 *  也就是 当spring容器对象被创建以后 我就会被执行
 *
 */
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("我是spring工厂加的亲戚");

        //我整一批清单 放进去!!!!
        /*for (int i = 0; i < 1000; i++) {
            GenericBeanDefinition beanDefinition=new GenericBeanDefinition();

            beanDefinition.setBeanClass(Object.class);
            beanDefinition.setScope("singleton");
            beanDefinition.setAbstract(false);

            BeanDefinitionRegistry registry= (BeanDefinitionRegistry) beanFactory;
            registry.registerBeanDefinition("我的是亲戚家的二大爷的儿子的朋友"+i+"号",beanDefinition);
        }*/


        GenericBeanDefinition beanDefinition=new GenericBeanDefinition();

        /*它只要指向是一个 实现了factoryBean 接口对象  */
        beanDefinition.setBeanClass(DaoFactoryBean.class);
        beanDefinition.setScope("singleton");
        beanDefinition.setAbstract(false);
        beanDefinition.setSynthetic(false);



        BeanDefinitionRegistry registry= (BeanDefinitionRegistry) beanFactory;
        registry.registerBeanDefinition("userDao",beanDefinition);










    }
}
